package kr.ac.skhu.m.data;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import kr.ac.skhu.m.value.InfoValue;

import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Source;

public class IndexInfoData {
	
	private String url;

	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
	public IndexInfoData() {
	
	}
	public IndexInfoData(String url) {
		this.url = url;
	}
	
	public List<InfoValue> getInfoValue() throws Exception {
		
		//해당 URL 페이지를 가져온다.
		Source source = new Source(new URL(url));

		//메소드 찾기를 위해 시작부터 끝까지 태그들만 parse 한다 (?)
		source.fullSequentialParse();
		
		/**
		 * 학사안내 데이터 가져오기
		 */
		List<InfoValue> infoValueList = new ArrayList<InfoValue>();
		
		Element info = source.getAllElementsByClass("info").get(0);
		
		List<Element> dayList = info.getAllElementsByClass("day");
		List<Element> txtList = info.getAllElementsByClass("txt");
			
		int listSize = dayList.size();
		
		for(int i=0; i<listSize; i++){
			
			InfoValue infoValue = new InfoValue();
			
			infoValue.setDay(dayList.get(i).getTextExtractor().toString());
			infoValue.setTxt(txtList.get(i).getTextExtractor().toString());
			
			infoValueList.add(infoValue);
			
		}
		
		return infoValueList;
	}
	
			
}
